<?php
namespace slinks\core\dependencyInjectionExt;

use slinks\core\DependencyInjection\Container;
use slinks\core\DependencyInjection\ParameterBag\ParameterBagInterface;

/**
 * Extended container that supports Auto Registering of namespaces.
 *
 * @author navid
 */
class ContainerExt extends Container
{
    /**
     * Constructor.
     */
    public function __construct(ParameterBagInterface $parameterBag = null)
    {
        parent::__construct($parameterBag);
        
        // register namespaces
        if($this->hasParameter(ContainerConstants::PARAM_AUTO_NAMESPACES)){
            $loader = new \slinks\common\UniversalClassLoader();
            
            $namespaces = $this->getParameter(ContainerConstants::PARAM_AUTO_NAMESPACES);
            
            foreach($namespaces as $namespace){ 
                $loader->registerNamespace($namespace[0],$namespace[1]);
            }
            
            $loader->register();
        }
    }
}

